import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Sumo here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Sumo extends Enemigos
{
    private int Speed;
    private int Salud ;
    private int animationCounter;
    private boolean moveLeft;
    private boolean isDead = false;
    
    private Cuchillo cuchillo;
    private Elixir elixir;
    private Ninja ninja;
    private GreenfootSound DagaEncajada;
     
    private final GreenfootImage WalkRight0 = new GreenfootImage("sumoC0.png");
    private final GreenfootImage WalkRight1 = new GreenfootImage("sumoC1.png");
    private final GreenfootImage WalkLeft0 = new GreenfootImage(WalkRight0);
    private final GreenfootImage WalkLeft1 = new GreenfootImage(WalkRight1);
  
    public Sumo(){
      Salud = 300;
      Speed = 1;
      animationCounter = 0;
      isDead = false;
      WalkLeft0.mirrorHorizontally();
      WalkLeft1.mirrorHorizontally();
      
      moveLeft = true;
      DagaEncajada = new GreenfootSound("DagaEncajada.wav");
    }
    /**
     * Act - do whatever the Sumo wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
       checaColision();
       if(isDead == false){
        if(ninjaCerca()){
          if(moveLeft)
          mueveLeft();
          else
          mueveRight();
          }
         }
    }  
    
    public void mueveLeft()
    {
        setLocation (this.getX() - Speed, this.getY());
        animationCounter ++;  
        
        if(animationCounter < 6)
           setImage(WalkLeft0);
        else if(animationCounter < 12)
           setImage(WalkLeft1);
           else if(animationCounter == 12)
             animationCounter = 0;
    }
    
     public void mueveRight()
    {
        setLocation (this.getX() + Speed, this.getY());
        animationCounter ++;  
        
        if(animationCounter < 6)
           setImage(WalkLeft0);
        else if(animationCounter < 12)
           setImage(WalkLeft1);
           else if(animationCounter == 12)
             animationCounter = 0;
    }
    
    public boolean ninjaCerca(){
       Niveles mundo = (Niveles)this.getWorld();
       ninja = mundo.ninja();
       
       if( ninja.ninjaX() < this.getX()) 
           moveLeft = true;
           else
           moveLeft = false;
           
       if(this.getX() - 300 >= ninja.ninjaX()  || this.getX() + 300 <=  ninja.ninjaX())
            return false;
            else
            return true;
            
           
          }
          
        
    public void checaColision(){
       
        Niveles mundo = (Niveles)this.getWorld();
        ninja = mundo.ninja;
       
        if(isTouching(Daga.class)){
             DagaEncajada.play();
             removeTouching(Daga.class);
             setLocation (this.getX()+10, this.getY());
             Salud -= 50;
        
                    
        }
        
        if(isTouching(Onda.class)){
            DagaEncajada.play();
            removeTouching(Onda.class);
            setLocation (this.getX()+10, this.getY());
            Salud -= 50;
                          
        }
        
         if(Salud <= 0){
              ninja.aumentaPuntos(10);
              cuchillo = new Cuchillo();
              mundo.addObject(cuchillo, this.getX(), this.getY()+10);
              
              elixir = new Elixir();
              mundo.addObject(elixir, this.getX(), this.getY()+10);
              getWorld().removeObject(this);
              isDead = true; 
           }
    
       }      
          
          
}
